package com.schoolcloud.social.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.schoolcloud.common.model.PageDTO;
import com.schoolcloud.social.entity.SocEvents;
import com.schoolcloud.social.query.EventQuery;
import com.schoolcloud.social.service.SocEventsService;
import com.schoolcloud.social.mapper.SocEventsMapper;
import com.schoolcolud.daomybatisplus.dto.MpPageUtil;
import org.springframework.stereotype.Service;

/**
 * @author hongmizfb
 * @description 针对表【soc_events】的数据库操作Service实现
 * @createDate 2025-02-28 08:27:49
 */
@Service
public class SocEventsServiceImpl extends ServiceImpl<SocEventsMapper, SocEvents>
        implements SocEventsService {


    @Override
    public PageDTO<SocEvents> getEventPage(EventQuery query) {
        String keywords = query.getKeywords();
        String sortBy = query.getSortByColumn();
        Page<SocEvents> page = lambdaQuery().like(StrUtil.isNotBlank(keywords), SocEvents::getTitle, keywords)
                .page(query.toMpPage());
        return MpPageUtil.of(page, SocEvents.class);
    }

    @Override
    public Long getUserPublishEventCount(Integer userId) {
        return lambdaQuery().eq(SocEvents::getOrganizerId, userId).count();
    }

}




